package com.bysc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.bysc.pojo.Result;
import com.bysc.pojo.entity.Task;
import com.bysc.service.TasksService;

@RestController
@RequestMapping("/tasks")
@Api(tags = "tasks相关接口")
public class TasksController {

    @Autowired
    private TasksService tasksService;

    /**
     * 查询任务列表
     * @return
     */
    @GetMapping
    @ApiOperation(value = "查询任务列表")
    public Result<List<Task>> getAllTask() {
        System.out.println("查询任务列表");

        List<Task> taskList = tasksService.getAllTask();

        return Result.success(taskList);
    }

    /**
     * 添加任务
     * @param task
     */
    @PostMapping
    @ApiOperation(value = "添加任务")
    public Result addTask(@RequestBody Task task) {
        System.out.println("添加任务" + task);

        tasksService.add(task);

        return Result.success();
    }

    /**
     * 删除任务
     * @param id
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除任务")
    public Result deleteTask(@PathVariable Integer id) {
        System.out.println("删除" + id + "号任务");

        tasksService.deleteById(id);

        return Result.success();
    }
}
